<template>
	<view class="p_bg_all">
		<view class="p_margin_t_32">
			<view class="form_list" @click="getChangeOrder">
				<view class="form_label">订单</view>
				<view class="p_font_28 p_color_b2 p_flex_1 p_text_r" v-if="!orderName">请选择</view>
				<view class="p_font_28 p_flex_1 p_text_r" v-else>{{orderName}}</view>
				<view style="width: 48rpx;"></view>
				<image src="https://dy.sykj365.com/uploads/mini/youjiantou@2x.png" class="p_img_48"></image>
			</view>
			<view class="form_list" @click="isRiseShow = true">
				<view class="form_label">抬头</view>
				<view class="p_font_28 p_color_b2 p_flex_1 p_text_r" v-if="!lookUpInfo.id">请选择</view>
				<view class="p_font_28 p_flex_1 p_text_r" v-else>{{lookUpInfo.name}}</view>
				<view style="width: 48rpx;"></view>
				<image src="https://dy.sykj365.com/uploads/mini/youjiantou@2x.png" class="p_img_48"></image>
			</view>
			<view class="form_list">
				<view class="form_label">开票金额</view>
				<view class="p_font_28 p_color_b2 p_flex_1 p_text_r" v-if="!orderName">默认为订单金额</view>
				<view class="p_font_28 p_flex_1 p_text_r" v-else>{{allPrice}}元</view>
			</view>
		</view>
		<view class="p_btn" @click="getSubmit">
			<view>确认开票</view>
		</view>
		<!--  -->
		<rise ref="viewR" :isShow="isRiseShow" @getLookUp="getLookUp" @getClose="isRiseShow = false"></rise>
	</view>
</template>

<script>
	import rise from './components/rise.vue';

	export default {
		components: {
			rise
		},
		data() {
			return {
				isRiseShow: false,
				orderName: '',
				orderIds: '',
				lookUpInfo: {},
				allPrice: 0,
			}
		},
		onShow() {
			if (uni.getStorageSync('riseDataUpdate')) {
				let id_ = this.lookUpInfo.id ? this.lookUpInfo.id : '';
				this.$refs.viewR.getListData(id_);
				uni.removeStorageSync('riseDataUpdate');
			}
			if (uni.getStorageSync('invoiceOrder')) {
				let orderList = JSON.parse(uni.getStorageSync('invoiceOrder'));
				let orderNameList = [];
				let orderIdsList = [];
				let p_ = 0;
				orderList.forEach((n) => {
					orderName.push(n.name);
					orderIdsList.push(n.id);
					p_ += Number(n.order_price);
				})
				this.orderName = orderNameList.toString();
				this.orderIds = orderIdsList.toString();
				this.allPrice = p_;
				uni.removeStorageSync('invoiceOrder');
			}
		},
		methods: {
			getChangeOrder() {
				let ids = this.orderIds;
				getApp().getNavigateTo('/pages/my/order1?ids=' + ids);
			},
			getLookUp(item) {
				this.isRiseShow = false;
				this.lookUpInfo = item;
			},
			getSubmit() {
				if (!this.orderIds) return getApp().getMsg('请选择订单');
				if (!this.lookUpInfo.id) return getApp().getMsg('请选择抬头');

				this.$http.post(this.$api.invoice, {
					order_ids: this.orderIds,
					look_up_id: this.lookUpInfo.id
				}).then(res => {
					getApp().getMsg('申请成功', 'success');
					uni.setStorageSync('invoice');
					getApp().getBack();
				})
			}
		}
	}
</script>

<style lang="less">
</style>